<template>
  <div class="dashboard-container">
    <h1>系统仪表板</h1>
    
    <el-row :gutter="20" class="m-t-10">
      <el-col :span="6" v-for="(card, index) in statCards" :key="index">
        <el-card class="stat-card" :body-style="{ padding: '0px' }">
          <div class="card-content" :style="{ backgroundColor: card.bgColor }">
            <div class="card-icon">
              <el-icon :size="36" :color="card.iconColor">
                <component :is="card.icon"></component>
              </el-icon>
            </div>
            <div class="card-data">
              <p class="card-title">{{ card.title }}</p>
              <p class="card-value">{{ card.value }}</p>
              <p class="card-change" :style="{ color: card.changeColor }">
                {{ card.change }}
              </p>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    
    <el-row :gutter="20" class="m-t-20">
      <el-col :span="16">
        <el-card class="chart-card">
          <template #header>
            <div class="chart-header">
              <span>活跃用户趋势</span>
              <el-radio-group v-model="activeTimeRange" size="small">
                <el-radio-button label="week">周</el-radio-button>
                <el-radio-button label="month">月</el-radio-button>
                <el-radio-button label="year">年</el-radio-button>
              </el-radio-group>
            </div>
          </template>
          <div class="chart-container" ref="lineChartContainer">
            <!-- 这里使用图表组件，如ECharts -->
            <div class="chart-placeholder">
              图表组件占位
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="8">
        <el-card class="chart-card">
          <template #header>
            <div class="chart-header">
              <span>应用使用分布</span>
            </div>
          </template>
          <div class="chart-container" ref="pieChartContainer">
            <!-- 这里使用饼图组件 -->
            <div class="chart-placeholder">
              饼图组件占位
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    
    <el-row :gutter="20" class="m-t-20">
      <el-col :span="24">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>最近活动</span>
              <el-button type="text">查看更多</el-button>
            </div>
          </template>
          <el-table :data="recentActivities" stripe style="width: 100%">
            <el-table-column prop="time" label="时间" width="180" />
            <el-table-column prop="user" label="用户" width="120" />
            <el-table-column prop="app" label="应用" width="120" />
            <el-table-column prop="action" label="操作" />
            <el-table-column prop="status" label="状态" width="100">
              <template #default="scope">
                <el-tag :type="scope.row.status === '成功' ? 'success' : 'danger'">
                  {{ scope.row.status }}
                </el-tag>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { 
  Monitor, 
  User, 
  Promotion, 
  TrendCharts 
} from '@element-plus/icons-vue'

const activeTimeRange = ref('month')

const statCards = [
  {
    title: '应用总数',
    value: '12',
    change: '增长 20%',
    changeColor: '#67C23A',
    icon: 'Monitor',
    bgColor: '#ecf8ff',
    iconColor: '#409EFF'
  },
  {
    title: '活跃用户',
    value: '2,148',
    change: '增长 15%',
    changeColor: '#67C23A',
    icon: 'User',
    bgColor: '#f0f9eb',
    iconColor: '#67C23A'
  },
  {
    title: '本月调用',
    value: '38,297',
    change: '增长 25%',
    changeColor: '#67C23A',
    icon: 'Promotion',
    bgColor: '#fdf6ec',
    iconColor: '#E6A23C'
  },
  {
    title: '平均响应',
    value: '521ms',
    change: '下降 5%',
    changeColor: '#F56C6C',
    icon: 'TrendCharts',
    bgColor: '#fef0f0',
    iconColor: '#F56C6C'
  }
]

const recentActivities = [
  {
    time: '2023-07-02 14:23:01',
    user: '张三',
    app: '全域管理',
    action: '导出数据报表',
    status: '成功'
  },
  {
    time: '2023-07-02 13:45:12',
    user: '李四',
    app: '应用二',
    action: '更新用户权限',
    status: '成功'
  },
  {
    time: '2023-07-02 12:32:45',
    user: '王五',
    app: '全域管理',
    action: '删除历史记录',
    status: '失败'
  },
  {
    time: '2023-07-02 10:15:33',
    user: '赵六',
    app: '应用二',
    action: '创建新项目',
    status: '成功'
  },
  {
    time: '2023-07-02 09:01:22',
    user: '钱七',
    app: '全域管理',
    action: '修改系统配置',
    status: '成功'
  }
]
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
}

.dashboard-container h1 {
  margin-bottom: 20px;
  font-size: 24px;
  font-weight: 500;
  color: var(--text-color);
}

.m-t-10 {
  margin-top: 10px;
}

.m-t-20 {
  margin-top: 20px;
}

.stat-card {
  margin-bottom: 10px;
}

.card-content {
  display: flex;
  padding: 20px;
  border-radius: 4px;
}

.card-icon {
  margin-right: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-data {
  flex: 1;
}

.card-title {
  font-size: 14px;
  color: var(--text-color-secondary);
  margin-bottom: 5px;
}

.card-value {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 5px;
}

.card-change {
  font-size: 12px;
}

.chart-card {
  height: 350px;
  margin-bottom: 20px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-container {
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-placeholder {
  color: #909399;
  font-size: 16px;
  text-align: center;
  border: 1px dashed #dcdfe6;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 